(function (vc) {
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addShopHouseInfo: {
                shId: '',
                shName: '',
                shTypes: [],
                shType: '',
                shDesc: ''
            }
        },
        _initMethod: function () {
            vc.getDict('s_shop_house', "sh_type", function (_data) {
                $that.addShopHouseInfo.shTypes = _data;
            });
        },
        _initEvent: function () {
            vc.on('addShopHouse', 'openAddShopHouseModal', function () {
                $('#addShopHouseModel').modal('show');
            });
        },
        methods: {
            addShopHouseValidate() {
                return vc.validate.validate({
                    addShopHouseInfo: $that.addShopHouseInfo
                }, {
                    'addShopHouseInfo.shName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "仓库名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "仓库名称太长"
                        },
                    ],
                    'addShopHouseInfo.shType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "仓库类型不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "仓库类型格式错误"
                        },
                    ],
                    'addShopHouseInfo.shDesc': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "描述不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "描述太长"
                        },
                    ]
                });
            },
            saveShopHouseInfo: function () {
                if (!$that.addShopHouseValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addShopHouseInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addShopHouseInfo);
                    $('#addShopHouseModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    '/shopHouse/saveShopHouse',
                    JSON.stringify($that.addShopHouseInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addShopHouseModel').modal('hide');
                            $that.clearAddShopHouseInfo();
                            vc.emit('shopHouseManage', 'listShopHouse', {});
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddShopHouseInfo: function () {
                let _shTypes = $that.addShopHouseInfo.shTypes;
                $that.addShopHouseInfo = {
                    shName: '',
                    shTypes: _shTypes,
                    shType: '',
                    shDesc: ''
                };
            }
        }
    });
})(window.vc);
